package cn.dingkai.dao.impl;

import cn.dingkai.dao.Citydao;
import cn.dingkai.pojo.Province;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import utils.JDBCUtils;

import java.util.List;

/**
 * @Auther:dingkai
 * @date:2021/12/16 0016 下午 12:18
 * @Desc:
 */
public class CitydaoImpl implements Citydao {
    //注入JdbcTemplate对象
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public List<Province> queryById(int pid) {
        try {
            String sql = "select * from province where parentid = ?";
            return this.jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Province.class), pid);
        } catch (DataAccessException e) {
            e.printStackTrace();
            throw  new RuntimeException("查询失败！");
        }
    }
}

